package com.exartisan.customview.smartgalleryimageview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;

import com.exartisan.thanhdoanhn.R;

public class SmartGalleryView extends RelativeLayout {
	protected ZoomableImageView mImageView;

	protected Context mContext;
	 private ImageLoader imageLoader;

	public SmartGalleryView(Context ctx) {
		super(ctx);
		mContext = ctx;
		 imageLoader = new ImageLoader(mContext);
		init();

	}

	public SmartGalleryView(Context ctx, AttributeSet attrs) {
		super(ctx, attrs);
		mContext = ctx;
		init();
	}

	public ZoomableImageView getImageView() {
		return mImageView;
	}

	protected void init() {
		mImageView = new ZoomableImageView(mContext);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT);
		mImageView.setLayoutParams(params);
		//cheat user when loading image is fail
		Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.holder_blog);
		mImageView.setImageBitmap(bm);
		mImageView.setScaleType(ScaleType.CENTER);
		//
		mImageView.setOnClickListener((OnClickListener) mContext);
		this.addView(mImageView);
	}

	public void setUrl(String imageUrl) {
		// mImageView.setImageUrl(imageUrl);
		imageLoader.DisplayImage(imageUrl, mImageView,new OnLoadedImageListener() {
			
			@Override
			public void onFinish() {
				mImageView.setScaleType(ScaleType.MATRIX);
			}
		});

	}

}
